// pages/card2.js
var loaded=false;
Component({
    /**
     * 组件的属性列表
     */
    properties: {
        card: Object,
        path: Object
    },

    /**
     * 组件的初始数据
     */
    data: {
        font: true,
        picSrc: null,
        loaded: false
    },
    attached: function () {
        const that=this;
        setTimeout(function() {
            if (!loaded) {
                that.refreshSrc()
            }
        },3000)
    },

    /**
     * 组件的方法列表
     */
    methods: {
        getImg() {
            console.log(this.data)
            const file = require('../../lib/file.js');
            const dl = new file.File();
            console.log(0)
            const that = this;
            const trans = {
                tc: 'nmonster', rh: 'rmonster', tt: 'tmonster', cl: 'cmonster', lj: 'link'
            }
            if (this.data.card.ifm.type == "monster" && this.data.card.ifm.type2 == 'xg' && this.data.card.ifm.type3 == "lb") {
                var name = "l_emonster";
            }
            else if (this.data.card.ifm.type == "monster" && this.data.card.ifm.type2 != 'xg' && this.data.card.ifm.type3 != "lb") {
                var name = trans[this.data.card.ifm.type2];
            }
            else if (this.data.card.ifm.type == "monster" && this.data.card.ifm.type2 != 'xg' && this.data.card.ifm.type3 == "lb") {
                var name = "l_" + trans[this.data.card.ifm.type2];
            }
            else {
                return;
            }
            console.log(1)

            dl.getImg(name, function (res) {
                console.log(res);
                that.setData({
                    path: res
                })
            })
        },
        changeSrc() {
            this.setData({
                picSrc: "https://card-1257059753.cos.ap-guangzhou.myqcloud.com/" + (this.data.card.size < 0.5 ? 'mini' : 'pics_/pics_mini') + "/" + this.data.card.ifm._id + ".jpg"
            })
        },
        picLoaded() {
            let card=this.data.card;
            card.picShow=true;
            loaded=true;
            this.setData({
                card: card
            })
        },
        refreshSrc() {
            console.log('超时')
            const time=new Date();
            this.picSrc = "cloud://cards-2c53b0.6361-cards-2c53b0/" + this.data.card.size < 0.5 ? 'mini' : 'pic' + "/" + this.data.card.ifm._id + ".jpg&time="+time.getTime();
        }
    }
})

